package com.sjc.counter.demo;

import java.util.concurrent.TimeUnit;

/**
 * @Classname UserController
 * @Description 应用场景：统计下面两个接口(注册和登录）的响应时间和访问次数
 * @Date 2020/5/1 11:24
 * @Created by SangJiacun
 */
public class UserController {
    private Metrics metrics = new Metrics();

    public UserController(){
        metrics.startRepeatedReport(60, TimeUnit.SECONDS);
    }

    public void register(String telephone,String password){
        long startTimestamp = System.currentTimeMillis();
        metrics.recordTimestamp("regsiter",startTimestamp);
        // ...
        long respTime = System.currentTimeMillis() - startTimestamp;
        metrics.recordResponseTime("register",respTime);
    }

    public void login(String telephone,String password){
        long startTimestamp = System.currentTimeMillis();
        metrics.recordTimestamp("login",startTimestamp);
        // ...
        System.out.println("login");

        long respTime = System.currentTimeMillis() - startTimestamp;
        metrics.recordResponseTime("login",respTime);

    }
}
